package com.pureut.production.controller;


import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.production.domain.dto.SpunlaceOutputDetailDto;
import com.pureut.production.domain.vo.SpunlaceOutputDetailVo;
import com.pureut.production.domain.vo.UpdateProductionCheckVo;
import com.pureut.production.service.SpunlaceOutputDetailService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 水刺产出明细Controller
 *
 * @author: CM
 * @date: 2023/2/20  17:02
 */
@RestController
@RequestMapping("/spunlaceOutputDetail")
public class SpunlaceOutputDetailController extends BaseController {

    @Resource
    private SpunlaceOutputDetailService spunlaceOutputDetailService;

    /**
     * 新增水刺产出明细列表
     */
    @Log(title = "新增水刺产出明细列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody SpunlaceOutputDetailVo spunlaceOutputDetailVo) {
        return toAjax(spunlaceOutputDetailService.add(spunlaceOutputDetailVo));
    }

    /**
     * 水刺产出明细列表
     */
    @GetMapping("/list")
    public TableDataInfo selectOperationList(String moNumber) {
        startPage();
        // 查询工序信息列表
        List<SpunlaceOutputDetailDto> list = spunlaceOutputDetailService.getList(moNumber);
        return getDataTable(list);
    }

    /**
     * 补打
     */
    @GetMapping("/reprint/{ids}")
    public AjaxResult reprint(@PathVariable("ids") String ids) {
        return AjaxResult.success(spunlaceOutputDetailService.reprint(ids));
    }

    /**
     * 条码修正
     */
    @Log(title = "条码修正", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SpunlaceOutputDetailVo spunlaceOutputDetailVo) {
        return toAjax(spunlaceOutputDetailService.edit(spunlaceOutputDetailVo));
    }

    /**
     * 条码修正回显
     */
    @GetMapping("/editView/{id}")
    public AjaxResult editView(@PathVariable("id") Long id) {
        return AjaxResult.success(spunlaceOutputDetailService.editView(id));
    }

    /**
     * 根据物料号码获取明细数据(fegin调用)
     */
    @GetMapping("/getSpunlaceDetail")
    public AjaxResult getSpunlaceDetail(String materialNumber) {
        return AjaxResult.success(spunlaceOutputDetailService.getSpunlaceDetail(materialNumber));
    }

    /**
     * 根据制令单号获取明细数据(fegin调用)
     */
    @GetMapping("/getDetailList")
    public AjaxResult getDetailList(String orderNum){
        return AjaxResult.success(spunlaceOutputDetailService.getDetailList(orderNum));
    }

    /**
     * 根据品质检验状态来修改水刺产出明细的结果
     */
    @PostMapping("/spunlaceUpdateStatus")
    public AjaxResult spunlaceUpdateStatus(@RequestBody UpdateProductionCheckVo updateProductionCheckVo) throws Exception {
        return toAjax(spunlaceOutputDetailService.spunlaceUpdateStatus(updateProductionCheckVo));
    }

    /**
     * 品质处理之后回传物料等级
     */
    @PostMapping("/spunlaceUpdateGrade")
    public AjaxResult spunlaceUpdateGrade(@RequestBody UpdateProductionCheckVo updateProductionCheckVo) throws Exception {
        return toAjax(spunlaceOutputDetailService.spunlaceUpdateGrade(updateProductionCheckVo));
    }

    /**
     * 根据母卷号码查询详情(产品追溯feign)
     * @param productionNumber
     * @return
     */
    @GetMapping("/selectSpunlaceDetailList")
    public AjaxResult selectSpunlaceDetailList(String productionNumber){
        return AjaxResult.success(spunlaceOutputDetailService.selectSpunlaceDetailList(productionNumber));
    }


}
